﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Gift.Model;
using Gift.DAL;


namespace WebSite.cn.service
{
    public partial class birthdayLove : BasePage
    {
        DALGoods theGoods = new DALGoods();
        DALNews theNews = new DALNews();
    

        StringBuilder _sbLeftBody01 = new StringBuilder();

        public StringBuilder SbLeftBody01
        {
            get { return _sbLeftBody01; }
        
        }

        StringBuilder _sbLeftBody02 = new StringBuilder();

        public StringBuilder SbLeftBody02
        {
            get { return _sbLeftBody02; }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.GetArticleList();
        }

        public string WriterGoodsHtml()
        {
            StringBuilder sGoodsHtml = new StringBuilder();

            DataTable dtGoods = theGoods.GetList(" isnull(visible,0)=1 and isnull(isSale,0)=1 and termsId in(select id from tbTerms where termsName like '%生日关爱%')  order by goodsOrder ").Tables[0];

            int iRowIndex = 0;
            for (int i = 0; i < dtGoods.Rows.Count; i++)
            {
                if (i % 3 == 0)
                {
                    sGoodsHtml.Append("<tr>");

                }
                sGoodsHtml.AppendFormat("  <td class=\"card_pic\"><img src=\"/uploadfile/product/{0}\"  "
                                         + " onmouseover=\"this.className='htmer_img'\" onmouseout=\"this.className=\'htmer_img_none'\" /> </td> "
                                        + " <td  class=\"card_inst\"><p class=\"list_card_title\">{1}</p><p><em>兑换价：{2}福点</em></p> "
                                        + " <p><a href=\"{3}\" target=\"_self\" ><img src=\"/cn/serviceImages/submit.gif\" class=\"img_submit\" alt=\"\" /></a> </p> "
                                        + " </td> "
                                        , dtGoods.Rows[i]["smallPic"].ToString()
                                        , dtGoods.Rows[i]["goodsName"].ToString()
                                        , dtGoods.Rows[i]["changePoints"].ToString()
                                        , "/cn/goodsDetail.html?gid=" + dtGoods.Rows[i]["goodsId"].ToString()
                                        );
                iRowIndex++;
                if (iRowIndex % 3 == 0)
                {
                    sGoodsHtml.Append("</tr>");
                }
            }
            if (dtGoods != null)
            {
                if (dtGoods.Rows.Count % 3 == 1)
                {
                    sGoodsHtml.Append("<td column='4'></td></tr>");
                }
                else if (dtGoods.Rows.Count % 3 == 2)
                {
                    sGoodsHtml.Append("<td ></td><td></td></tr>");
                }
            }
            return sGoodsHtml.ToString();

        }

        void  GetArticleList()
        {

            DataTable table = theNews.GetList(10, "typeid in(select typeId from tbNewsType where typeName='生日关爱') and visible=1 and isnew=1", "newsOrder asc, updatetime desc").Tables[0];
            if (table != null)
            {
                int iRowIndex = 0;
                foreach (DataRow row in table.Rows)
                {
                    if (iRowIndex < 5)
                    {
                        _sbLeftBody01.AppendFormat("<li><span> <a href=\"{0}\" target='_blank' title=\"{1}\">{2}</a></span><span class=\"time\">[{3}]</span> </li>"
                                               , "/cn/news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString()
                                               , row["newsname"].ToString()
                                               , row["newsname"].ToString().Length > 15 ? fun.Left(row["newsname"].ToString(), 15) + ".." : row["newsname"].ToString()
                                               , row["updatetime"].ToString()
                                               );
                    }
                    else
                    {
                        _sbLeftBody02.AppendFormat("<li><span> <a href=\"{0}\" target='_blank' title=\"{1}\">{2}</a></span><span class=\"time\">[{3}]</span> </li>"
                                                , "/cn/news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString()
                                                , row["newsname"].ToString()
                                                 , row["newsname"].ToString().Length > 15 ? fun.Left(row["newsname"].ToString(), 15) + ".." : row["newsname"].ToString()
                                                , row["updatetime"].ToString()
                                                );
                    }
                    iRowIndex++;
                }
            }
          
          
        }

        public string GetHotArticleList()
        {
            StringBuilder sbLeftList = new StringBuilder();
            DataTable table = theNews.GetList(5, "typeid in(select typeId from tbNewsType where typeName='生日关爱') and visible=1 and isnew=1", "clicks desc, newsOrder asc").Tables[0];
            if (table != null)
            {
                foreach (DataRow row in table.Rows)
                {
                    sbLeftList.AppendFormat("<li><span> <a href=\"{0}\" target='_blank' title=\"{1}\">{2}</a></span><span class=\"time\">{3}</span> </li>"
                                           , "/cn/news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString()
                                           , row["newsname"].ToString()
                                             , row["newsname"].ToString().Length > 18 ? fun.Left(row["newsname"].ToString(), 18) + ".." : row["newsname"].ToString()
                                           , string.Empty
                                           );
                }
            }
            return sbLeftList.ToString();

        }
    }
}